package com.sc.service.impl.patrol;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.domain.patrol.PatrolPlan;
import com.sc.dto.PatrolPlanDTO;
import com.sc.mapper.patrol.PatrolPlanMapper;
import com.sc.result.PageResult;
import com.sc.service.patrol.PatrolPlanService;
import com.sc.vo.PatrolPlanVO;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 巡检计划
 * @author: Zuiliu
 * 添加服务层实现类
 **/
@Service
public class PatrolPlanServiceImpl extends ServiceImpl<PatrolPlanMapper, PatrolPlan> implements PatrolPlanService {

    @Override
    public PageResult<PatrolPlanVO> pageQuery(PatrolPlanDTO patrolPlanDTO) {
        int start = (patrolPlanDTO.getPageNum() - 1) * patrolPlanDTO.getPageSize();
        int end = patrolPlanDTO.getPageNum() * patrolPlanDTO.getPageSize();

        List<PatrolPlanVO> patrolPlanVOList = baseMapper.pageQuery(patrolPlanDTO);
        PageResult<PatrolPlanVO> page = new PageResult<>(patrolPlanVOList.size(), patrolPlanVOList.subList(start, Math.min(patrolPlanVOList.size(), end)));
        return page;
    }
}
